//
//  RegisterNextVC.m
//  SH_JSK
//
//  Created by 郑渊文 on 15/1/27.
//  Copyright (c) 2015年 asiainfo. All rights reserved.
//

#import "RegisterNextViewController.h"
#import "CommonMacro.h"
#import "UIImage+LXX.h"
#import "myTabBarViewController.h"


@interface RegisterNextViewController ()
{
    BOOL ifRead;
}
@property(nonatomic,copy)UITextField *passWord;
@property(nonatomic,copy)UITextField *certainPassWord;

@end

@implementation RegisterNextViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    ifRead = NO;
    self.view.backgroundColor = [UIColor whiteColor];
    [self layout];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)layout
{
    UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    [self.view addSubview:bgView];
    
    UIView *registView = [[UIView alloc]initWithFrame:CGRectMake(20,150, SCREEN_WIDTH-40, 160)];
    [bgView addSubview:registView];
    registView.layer.cornerRadius = 8;
    registView.layer.borderColor = UIColorWithRGBA(232, 234, 237, 1).CGColor;
    registView.layer.borderWidth = 1;
    
    [self.navigationController.navigationBar setTranslucent:NO];//设置navigationbar的半透明
    self.title = @"确认密码";//设置navigationbar上显示的标题
    [self.navigationController.navigationBar setBarTintColor:UIColorWithRGBA(89,214,158,1)];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];//设置navigationbar上左右按钮字体颜色
        
    //    UIView *line1 = [[UIView alloc]initWithFrame:CGRectMake(0, 30, SCREEN_WIDTH-20, 1)];
    UIView *line2 = [[UIView alloc]initWithFrame:CGRectMake(0, 60, SCREEN_WIDTH-40, 1)];
    UIView *line3 = [[UIView alloc]initWithFrame:CGRectMake(0, 110, SCREEN_WIDTH-40, 1)];
    
    //    line1 .backgroundColor = UIColorWithRGBA(232, 234, 237, 1);
    line2 .backgroundColor = UIColorWithRGBA(232, 234, 237, 1);
    line3 .backgroundColor = UIColorWithRGBA(232, 234, 237, 1);
    
    UIImageView *phoneImg = [[UIImageView alloc]initWithFrame:CGRectMake(20, 25, 12, 20)];
    phoneImg.image = [UIImage imageNamed:@"_0002s_0005_手机@2x"];
    [registView addSubview:phoneImg];
    
    UIImageView *passWordImg = [[UIImageView alloc]initWithFrame:CGRectMake(20, 75, 17, 20)];
    passWordImg.image = [UIImage imageNamed:@"_0002s_0008_密码@2x"];
    [registView addSubview:passWordImg];
    
    UIImageView *certainPassWordImg = [[UIImageView alloc]initWithFrame:CGRectMake(20, 125, 17, 20)];
    certainPassWordImg.image = [UIImage imageNamed:@"_0002s_0008_密码@2x"];
    [registView addSubview:certainPassWordImg];
    
    
    UILabel *phoneLab = [[UILabel alloc]initWithFrame:CGRectMake(60,20, SCREEN_WIDTH-40, 35)];
    phoneLab.text = _phoneNum;
    [registView addSubview:phoneLab];
    
    _passWord = [[UITextField alloc]initWithFrame:CGRectMake(60, 70, SCREEN_WIDTH-40, 35)];
    _passWord.placeholder = @"请输入密码";
     _passWord.secureTextEntry = YES;
    
    _certainPassWord = [[UITextField alloc]initWithFrame:CGRectMake(60, 120, 200, 35)];
    _certainPassWord.placeholder = @"请输入确认密码";
     _certainPassWord.secureTextEntry = YES;
    [registView addSubview:_passWord];
    [registView addSubview:_certainPassWord];
    
    //    [registView addSubview:line1];
    [registView addSubview:line2];
    [registView addSubview:line3];
    
    
    UIView *declareView = [[UIView alloc]initWithFrame:CGRectMake(20,320,SCREEN_WIDTH-40,50)];
    declareView.backgroundColor = [UIColor clearColor];
    [bgView addSubview:declareView];
    
    UIButton *ifReadDeclare = [[UIButton alloc] initWithFrame:CGRectMake(10,10,30,30)];
//    ifReadDeclare.backgroundColor = [UIColor redColor];
    [ifReadDeclare setImage:[UIImage imageNamed:@"框-"] forState:UIControlStateNormal];
    [ifReadDeclare setImage:[UIImage imageNamed:@"选中_"] forState:UIControlStateSelected];
    [ifReadDeclare addTarget:self action:@selector(changeifReadDeclare:) forControlEvents:UIControlEventTouchUpInside];
    [declareView addSubview:ifReadDeclare];
    
    
    UILabel *ReadDeclareLab = [[UILabel alloc] initWithFrame:CGRectMake(40,10,SCREEN_WIDTH-40,30)];
    [declareView addSubview:ReadDeclareLab];
    ReadDeclareLab.text = @"我已经阅读并同意《汇思顿服务协议》";
    ReadDeclareLab.textColor = [UIColor lightGrayColor];
    

    UIButton *nextTepBtn = [[UIButton alloc]initWithFrame:CGRectMake(20, 380, SCREEN_WIDTH-40, 50)];
    //    UIImage* image = [UIImage resizedImage:@"bg_green_button.9"];
    nextTepBtn.layer.cornerRadius = 8;
    nextTepBtn.backgroundColor = UIColorWithRGBA(89,214,158,1);
    [nextTepBtn setTitle:@"立即登陆" forState:UIControlStateNormal];
    [nextTepBtn addTarget:self action:@selector(nextTep) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:nextTepBtn];
  
}

-(void)nextTep
{
    if([_passWord.text length]==0){
        [self showSimpleAlertView:@"请输入密码"];
    }
   else if ([_passWord.text isEqualToString:_certainPassWord.text]==FALSE) {
        [self showSimpleAlertView:@"两次密码输入不一致"];
    }
    
    else if(ifRead==YES){
        
        NSString *userId = _phoneNum;
        NSString *userCode = _passWord.text;
        [[NSUserDefaults standardUserDefaults] setObject:userId forKey:@"userId"];
        [[NSUserDefaults standardUserDefaults] setObject:userCode forKey:@"userCode"];
        
        myTabBarViewController *myTableView = [[myTabBarViewController alloc]init];
        [self  presentViewController:myTableView animated:YES completion:nil];
    }else
    {
        [self showSimpleAlertView:@"请阅读申明"];
    }
    //此处发送请求
//    CreatUserInfo *cc= [[CreatUserInfo alloc]init];
////    [self presentViewController:cc animated:YES completion:nil];
//    [self.navigationController pushViewController:cc animated:YES];
}


- (void)changeifReadDeclare:(UIButton *)mySwitch
{
    mySwitch.selected = !mySwitch.selected;
    ifRead = mySwitch.selected;
//    _userCodeField.secureTextEntry = !mySwitch.selected;
}

-(void)showSimpleAlertView:(NSString*)message
{
    UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"提示信息"
                                                    message:message
                                                   delegate:nil
                                          cancelButtonTitle:@"确定"
                                          otherButtonTitles:nil];
    [alert show];
}



@end
